/**
 * GeneralResponseMessage.java
 * ************************** 
 * @date May 15, 2011
 * @author Michele Tamburini
 * 
 * **************************
 */
package infrastructureAPI.APIMessages;

import gossipServices.basic.nodeDescriptors.ConcreteNodeDescriptor;
import gossipServices.basic.nodeDescriptors.NodeDescriptor;
import infrastructureAPI.APIResponse;
import infrastructureAPI.Requester;
import messages.GeneralMessage;

/**
 * Description:
 * This class is an implementation of the ResponseMessage interface
 * and extends the GeneralMessage. It represents a reply message 
 * as an answer to a request. 
 * It uses the body of the message as the APIResponse.
 *
 */
public class GeneralResponseMessage extends GeneralMessage implements
		ResponseMessage {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * @param sender
	 * @param dest
	 * @param body
	 */
	public GeneralResponseMessage(NodeDescriptor sender, NodeDescriptor dest,
			Object body) {
		super(sender, dest, body);
	}
	
	/**
	 * 
	 */
	public GeneralResponseMessage() { }

	/**
	 * This is an experiment where the Requester is translated into a 
	 * NodeDescriptor. In this modification the name of the node 
	 * becomes the registered service, the address maintains its 
	 * natural meaning, finally the age of the NodeDescriptor stores
	 * the port, through which the rmiregistry of the destination
	 * is listening for response(s).
	 * 
	 * @param dest
	 * @param requester
	 * @param body
	 */
	public GeneralResponseMessage(NodeDescriptor sender, Requester requester,
			APIResponse body) {
		super(sender, new ConcreteNodeDescriptor(requester.getRegisteredService(),
				requester.getNodeAddress(), requester.getPort()), body);
	}
	
	public GeneralResponseMessage(NodeDescriptor sender){
		this.sender = sender;
	}

	@Override
	public APIResponse getAPIResponse() {
		return (APIResponse) body;
	}
	
	public String toString(){
		String ret = new String("");
		ret += id + " " + sender;		
		return ret;
	}

}
